<!DOCTYPE html>
<html>
<!-- 
     This probably needs to be renamed index.html for deployment.
     Specifically, it needs to be the default page for whatever
     directory it is in.
-->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">

    <!-- this gmaps key generated for http://openlayers.org/dev/ -->
    <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA9XNhd8q0UdwNC7YSO4YZghSPUCi5aRYVveCcVYxzezM4iaj_gxQ9t-UajFL70jfcpquH5l1IJ-Zyyw'></script>
    <!-- Localhost key -->
     <!--<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTS6gjckBmeABOGXIUiOiZObZESPg'></script>-->
<script src="http://openlayers.org/dev/lib/OpenLayers.js"></script>

<script>

function runMVS() {
    OpenLayers.ProxyHost = '/proxy/?url='; 
    if (document.location.protocol != "file:") {
        theArgs = OpenLayers.Util.getParameters();
    } else {
        theArgs = {};
        theArgs.center = "0,0";
        theArgs.zoom = "0";            
        theArgs.data = "textfile.txt";
        theArgs.controls = 'panzoom,mouse';
        theArgs.layers = 'openlayers';
    }


    // ----
    // TODO: Handle all this parsing better.
    var safeArgs = {};

    var DEFAULT_LAT = 0;
    var DEFAULT_LON = 0;
    var DEFAULT_ZOOM_LEVEL = 0;
    var DEFAULT_CONTROLS = ['panzoom','mouse'];
    var DEFAULT_LAYERS = ['openlayers'];
    
    var IDX_LAT = 0;
    var IDX_LON = 1;

    safeArgs.centerLat = theArgs.center ? 
        parseFloat(theArgs.center.split(",")[IDX_LAT]) : DEFAULT_LAT;
    
    safeArgs.centerLon = theArgs.center ? 
        parseFloat(theArgs.center.split(",")[IDX_LON]) : DEFAULT_LON;

    safeArgs.zoom = theArgs.zoom ? parseInt(theArgs.zoom) : DEFAULT_ZOOM_LEVEL;
    
    safeArgs.controls = theArgs.controls ? 
        theArgs.controls.split(",") : DEFAULT_CONTROLS;
    
    safeArgs.layers = theArgs.layers ? 
        theArgs.layers.split(",") : DEFAULT_LAYERS;
    
    safeArgs.data = theArgs.data; // TODO: Make this "safe".
    safeArgs.marker = theArgs.marker; // TODO: Make this "safe".
    
    // -----
    var theMVS = new OpenLayers.Map('map', {controls: [], maxResolution: 'auto'});
    for(var i = 0; i < safeArgs.controls.length; i++) {
        switch(safeArgs.controls[i]) {
            case 'panzoombar':
                theMVS.addControl(new OpenLayers.Control.PanZoomBar());
                break;
            case 'panzoom':
                theMVS.addControl(new OpenLayers.Control.PanZoom());
                break;
            case 'layerswitcher':
                theMVS.addControl(new OpenLayers.Control.LayerSwitcher());
                break;
            case 'mouse':
                theMVS.addControl(new OpenLayers.Control.MouseDefaults());
                break;
        }
    }
    for(var i = 0; i < safeArgs.layers.length; i++) {
        switch(safeArgs.layers[i]) {
            case 'openlayers':
                theMVS.addLayer(
                  new OpenLayers.Layer.WMS( "OpenLayers WMS", 
                        "http://vmap0.tiles.osgeo.org/wms/vmap0", 
                        {layers: 'basic'} )
                  );
                break;
            case 'nasa': 
                theMVS.addLayer(
                    new OpenLayers.Layer.WMS("NASA Mosaic", 
                       "http://t1.hypercube.telascience.org/cgi-bin/landsat7",
                       {"EXCEPTIONS" : "application/vnd.ogc.se_inimage",
                        "format" : "image/jpeg",
                        layers:"landsat7"}
                       ));
                break;
            case 'gmaps':
                theMVS.addLayer(
                    new OpenLayers.Layer.Google( "Google" , {type: G_HYBRID_MAP })
                );
                break;
        }
    }
    theMVS.setCenter(new OpenLayers.LonLat(safeArgs.centerLon, safeArgs.centerLat), safeArgs.zoom);

    if (safeArgs.marker) {
        var m = new OpenLayers.Layer.Markers("Marker");
        m.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(safeArgs.centerLon, safeArgs.centerLat)));
        theMVS.addLayer(m);
    }
    if (safeArgs.data) {
        theMVS.addLayer(new OpenLayers.Layer.Text("Data", {location: safeArgs.data}));
    }

}
</script>
</head>
<body style="margin:0px;"
      onload="runMVS();">
<div id="map"
     style="width: 100%; height: 100%;
            background: lightyellow;
           "></div>
</body>
</html>
